﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlServerCe;
using System.Collections;

namespace TVRIP.DB
{
    class FisicoDB: BaseDB
    {
        private static FisicoDB instance;

        private FisicoDB() { }

        public static FisicoDB getInstance()
        {
            if (instance == null)
            {
                instance = new FisicoDB();
            }
            return instance;
        }

        //checa se código informado existe na base.
        public bool checkPlaqueta(string plaqueta)
        {
            bool result = false;
            try
            {
                this.open();
                SqlCeCommand command = new SqlCeCommand("select * from TB_CCUSTO where cd_fis_ccusto =@codCcusto;", this.conn);
                command.Parameters.AddWithValue("@codCcusto", plaqueta);
                SqlCeDataReader rdr = command.ExecuteReader();
                while (rdr.Read())
                {
                    result = true;
                }
            }
            finally
            {
                this.close();
            }
            return result;
        }

        //checa se código informado existe na base.
        public ArrayList selectByPlaqueta(string plaqueta)
        {
            ArrayList result = new ArrayList();
            try
            {
                this.open();
                SqlCeCommand command = new SqlCeCommand("select * from TB_CCUSTO where cd_fis_ccusto =@codCcusto;", this.conn);
                command.Parameters.AddWithValue("@codCcusto", codCcusto);
                SqlCeDataReader rdr = command.ExecuteReader();
                while (rdr.Read())
                {
                    result = true;
                }
            }
            finally
            {
                this.close();
            }
            return result;
        }

        //método que salva os valores lidos no método selectByCodPad.
        private Fisico toFisico(SqlCeDataReader reader)
        {
            Fisico codPad = new CodPad();
            codPad.COD_PAD = reader.GetString(0);
            codPad.DS_PAD = reader.GetString(1);
            try
            {
                codPad.MARCA = reader.GetString(2);
            }
            catch (Exception) { codPad.MARCA = "NÂO POSSUI"; }

            try
            {
                codPad.MODELO = reader.GetString(3);
            }
            catch (Exception) { codPad.MODELO = "NÂO POSSUI"; }

            try
            {
                codPad.CAPACIDADE = reader.GetString(4);
            }
            catch (Exception) { codPad.CAPACIDADE = "NÂO POSSUI"; }

            try
            {
                codPad.VIDA_UTIL = reader.GetString(5);
            }
            catch (Exception) { codPad.VIDA_UTIL = "NÂO POSSUI"; }

            return codPad;
        }
    }
}
